<template>
  <div class="m-user">
    <template v-if="user">
      欢迎您，<span>{{ user }}</span>
      [<nuxt-link to="/exit">退出</nuxt-link>]
    </template>
    <template v-else>
      <nuxt-link
        to="/login"
        class="login"
      >立即登录</nuxt-link>
      <nuxt-link 
        to="/register" 
        class="register"
      >注册</nuxt-link>
    </template>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: ''
    }
  },
  async mounted() {
    const {status, data: {user}} = await this.$axios('/users/getUser')
    if (status === 200) {
      this.user = user
    }
  }
}
</script>

<style lang="stylus" scoped>
  .m-user
    display inline-block
    margin-left 15px
    .login
      margin-left 10px
      color #31bbac
    .register
      margin-left 10px
      color #999999
      &:hover
        color #31bbac
</style>
